package com.xuan.yupao.exception;


import com.xuan.yupao.common.ErrorCode;
import com.xuan.yupao.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result<?> businessExceptionHandler(BusinessException e) {
        log.error("BusinessExcept: " + e.getDescription(), e);

        System.out.println(e.getDescription());
        return Result.error(e.getCode(), e.getMessage(), e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result<?> runtimeExceptionHandler(RuntimeException e) {
        log.error("runtimeException: ", e);

        return Result.error(ErrorCode.SYSTEM_ERROR);
    }
}
